# 导入模块
import re
import random

# \b 匹配单词边界
print(re.search(r'he\b', 'hello'))  # None
print(re.search(r'hello\b', 'hello_'))  # None

# \B 匹配非单词边界
print(re.search(r'he\B', 'he'))  # None
print(re.search(r'he\B', 'hello'))  # <re.Match object; span=(0, 2), match='he'>

#若需要多次似使用同一个正则表达式，可以将其编译
exp = re.compile(r'[0-9]*')
print(type(exp))#<class 're.Pattern'>

print(exp.search('7834328'))#<re.Match object; span=(0, 7), match='7834328'>

# 获取匹配的内容
result=re.search(r'\d* \d*','123 456')
print(result.group())#110
print(result.group(1))#110
print(result.group(2))#110

print(result.end(1))#110
print(result.start(1))#110

